﻿using Company.Database.Entities;
using Company.Database.Interfaces;
using Company.Demo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using TookKit.Mvvm.Attributes;
using TookKit.Mvvm.Bindings;
using TookKit.Mvvm.Enums;
using TookKit.Mvvm.Events;

namespace Company.Demo.ViewModels
{
    [DependencyInjection(Lifetime.Singleton)]
    internal class LoginViewModel
    {
        private User user = new User() { UserName = "admin", Password = "12345678" };
        public User User
        {
            get { return user; }
            set { user = value; }
        }


        public ICommand LoginCommand { get; }

        private IUserRepository UserRepository { get; }
        public LoginViewModel(IUserRepository userRepository)
        {
            UserRepository=  userRepository; 
            LoginCommand = new RelayCommand(Login);

            /* 
             * HKCamera
             * DHCamera  面向接口编程
             * 
             * 对修改封闭，对扩展开放  = 开闭原则 
             * 
             * ICamera: 打开相机  取图 关闭相机
             * HKCamera:ICamera  => 打开相机  取图 关闭相机 HK相机模块
             * DHCamera:ICamera  => 打开相机  取图 关闭相机（新的DH模块）
             */

        }

        private void Login()
        {
            //用户登录
            var entity = UserRepository.GetAll().FirstOrDefault(t => t.UserName == User.UserName && t.Password == User.Password);
            if (entity != null)
            {
                EventBus.Default.Publish(this, new LoginMessage(entity));
            }
        }
    }
}
